package dblink

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

type (
	ConnectCommon interface {
		GetMySqlCrm(shorten string) error
	}
	defaultConnectCommon struct {
		DataSource string
	}
)

func NewConnectCommon(dataSource string) *defaultConnectCommon {
	return &defaultConnectCommon{
		DataSource: dataSource,
	}
}
func (d defaultConnectCommon) MysqlGenerateGorm(dataSourceName string, tablePrefix string) (*gorm.DB, error) {
	//启动Gorm支持
	db, err := gorm.Open(mysql.Open(dataSourceName), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			TablePrefix:   tablePrefix, // 表名前缀，`User` 的表名应该是 `t_users`
			SingularTable: true,        // 使用单数表名，启用该选项，此时，`User` 的表名应该是 `t_user`
		},
	})
	return db, err
}
